package com.xfp.controller;


import com.xfp.pojo.dto.NodeDto;
import com.xfp.pojo.dto.newNodeDto;
import com.xfp.pojo.entity.Business;
import com.xfp.pojo.entity.Node;
import com.xfp.pojo.entity.Vm;
import com.xfp.pojo.vo.*;
import com.xfp.result.Result;
import com.xfp.service.NodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vm-service")
@Slf4j
@Api(tags = "点位管理")
public class NodeController {

    @Autowired
    private NodeService nodeService;

    @GetMapping("/node/search")
    @ApiOperation(("点位搜索"))
    public RegionDetailedQueryVo pageNode(NodeDto dto) throws Exception {
        log.info("查看区域详情：{}",dto);
        RegionDetailedQueryVo vo = nodeService.pageNode(dto);
        return vo;
    }

    /**
     * 查询商圈列表
     */
    @GetMapping("/businessType")
    @ApiOperation("查询商圈列表")
    public List<Business> pageBusinessType(){
        log.info("查询商圈列表");
        BusinessVo vo = nodeService.findBusinessList();
        return vo.getCurrentPageRecords();
    }

    /**
     * 新增点位
     * @param dto
     * @return
     * @throws Exception
     */
    @PostMapping("/node")
    @ApiOperation("新增点位")
    public Boolean insertNode(@RequestBody newNodeDto dto) throws Exception {
        log.info("新增点位");
        nodeService.insertNode(dto);
        return true;
    }

    /**
     * 修改点位
     */
    @PutMapping("/node/{id}")
    @ApiOperation("修改点位")
    public Boolean updatNode(@PathVariable String id,@RequestBody newNodeDto dto){
        log.info("修改点位：{},{}",id,dto);
        nodeService.updateNode(id,dto);
        return true;
    }

    /**
     * 删除点位
     */
    @DeleteMapping("/node/{nodeId}")
    @ApiOperation("删除点位")
    public Boolean deleteNode(@PathVariable String nodeId){
        log.info("删除点位：{}",nodeId);
        nodeService.delete(nodeId);
        return true;
    }

    /**
     * 点位详情
     */
    @GetMapping("/node/vmList/{id}")
    @ApiOperation("点位详情")
    public List<Vm> findNode(@PathVariable String id){
        log.info("点位详情:{}",id);
        NodeVmListVo list = nodeService.findNode(id);
        return list.getVmList();
    }

}
